package com.shujia.tf

import org.apache.flink.api.common.functions.FilterFunction
import org.apache.flink.streaming.api.scala._

object Demo3Filter {
  def main(args: Array[String]): Unit = {
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    val listDS: DataStream[Int] = env.fromCollection(List(1, 2, 3, 4, 5, 6, 7, 8, 9))

    //scala api
    val scalaApiDS: DataStream[Int] = listDS.filter(i => i % 2 == 1)

    //    scalaApiDS.print()


    val javaApiDS: DataStream[Int] = listDS.filter(new FilterFunction[Int] {
      /**
        * 将数据一条一条传递给filter ，filter返回true保留数据，filter返回false过滤数据
        *
        * @param value: 一行数据
        * @return
        */
      override def filter(value: Int): Boolean = {
        value % 2 == 1
      }
    })

    javaApiDS.print()

    env.execute()

  }

}
